/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ec.com.farmaciassantamartha.comprobantes.portal.sql;

import ec.com.farmaciassantamartha.comprobantes.portal.util.ConexionSQL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Maestria
 */
public class TipoDocumentoSQL {

    public static int obtenerId(String codigo) {
        PreparedStatement pst = null;
        Connection cn = null;
        int id = 0;
        try {
            cn = ConexionSQL.getConexion();
            pst = cn.prepareStatement("SELECT id FROM tipo_documento WHERE codigo=?");
            pst.setString(1, codigo);
            ResultSet rs = pst.executeQuery();
            while (rs.next()) {
                id = rs.getInt(1);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
            if (cn != null) {
                try {
                    cn.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }
        return id;
    }
    
    public static void main(String[] args) {
        System.out.println(obtenerId("04"));
    }
}
